package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.CartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description: 购物车相关操作
 * @author: nianqiang
 * @Version: V1.0
 */
@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "购物车相关操作")
public class CartController {

		@Autowired
		private CartService cartService;


		@PostMapping("/add")
		@ApiOperation("添加购物车")
		public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
				cartService.add(shoppingCartDTO);
				return Result.success();
		}

		@GetMapping("/list")
		@ApiOperation("查询我的购物车")
		public Result<List<ShoppingCart>> list() {
				List<ShoppingCart> cartList = cartService.list();
				return Result.success(cartList);
		}

}
